package com.leyou.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.leyou.entity.StockEntity;
import com.leyou.service.StockService;

import com.leyou.api.R;



/**
 * 库存表，代表库存，秒杀库存等信息
 *
 * @author Daifeng
 * @email 2661184062@qq.com
 * @date 2020-12-25 16:44:45
 */
@RestController
@RequestMapping("leyou/stock")
public class StockController {
    @Autowired
    private StockService stockService;



    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
 //   @RequiresPermissions("leyou:stock:info")
    public R info(@PathVariable("skuId") Long skuId){
		StockEntity stock = stockService.getById(skuId);

        return R.ok().put("stock", stock);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
  //  @RequiresPermissions("leyou:stock:save")
    public R save(@RequestBody StockEntity stock){
		stockService.save(stock);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
  //  @RequiresPermissions("leyou:stock:update")
    public R update(@RequestBody StockEntity stock){
		stockService.updateById(stock);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
   // @RequiresPermissions("leyou:stock:delete")
    public R delete(@RequestBody Long[] skuIds){
		stockService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

}
